﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Text;
using System.Collections;
using System.Data.OracleClient;
using Xiaov.SmartWeb.Application.SupCan;

namespace Xiaov.SmartWeb.Application.HXZB.Tzfx
{
    public partial class TzzbIndexData : System.Web.UI.Page
    {        
        protected void Page_Load(object sender, EventArgs e)
        {            
            string xmlbid = Request.QueryString["xmlbid"];
            string nf = Request.QueryString["nf"];
            string yf = Request.QueryString["yf"];


            if ((nf != null) && (yf != null))
            {
                string sql = "";
                string dataString = "";
                if (Request.QueryString["sfdj"] != null && Request.QueryString["sfdj"].ToString() != "")//判断是否是单井
                {
                    sql = "select zbmc,htgzl,htje,htbh,bnljjhgzl,bnljsjgzl,bnljjhtz,zksljjhtz,bnljsjtz,zksljsjtz from v_cj_yt_tzzb where xmgcid='" + xmlbid + "' and nf=" + nf + " and yf=" + yf;
                    dataString = "zbmc,htgzl,htje,htbh,bnljjhgzl,bnljsjgzl,bnljjhtz,zksljjhtz,bnljsjtz,zksljsjtz";
                }
                else
                {
                    #region 判断是否到项目级别
                    sql = "select pxbm from yt_xmlbb where pxbm like '" + xmlbid + "%'";
                    DataSet dsJb = Maticsoft.DBUtility.DbHelperOra.Query(sql);
                    #endregion
                    if (dsJb.Tables[0].Rows.Count > 1)//传递的参数项目类别不为类别末级
                    {
                        sql = "select a.zbmc,htje,bnljjhtz,bnljsjtz,xmgcid,'类别' jh from v_cj_yt_tzzb a,yt_xmlbb b where b.pxbm='" + xmlbid + "' and a.pxbm like b.pxbm||'%' and length(a.pxbm)=" + (xmlbid.Length + 2)
                           + " and a.nf=" + nf + " and a.yf=" + yf;
                    }
                    else if (dsJb.Tables[0].Rows.Count == 1)//传递的参数项目类别id为类别末级
                    {
                        sql = "select trim(zbmc) zbmc,htje,bnljjhtz,bnljsjtz,xmgcid,'项目' jh from v_cj_yt_tzzb where sj='" + xmlbid + @"' and nf="
                            + nf + " and yf=" + yf + " and xmgcid_lb='项目'";
                    }
                    else if (dsJb.Tables[0].Rows.Count < 1)//传递的参数项目类别id为项目id
                    {
                        sql = @"select trim(b.jh) jh,trim(a.zbmc) zbmc,a.htje,a.bnljjhtz,a.bnljsjtz,a.xmgcid 
                        from v_cj_yt_tzzb a left join zjyb_zjyb00 b on trim(a.zbmc)=trim(b.jh)                         
                        where a.sj='" + xmlbid + @"' and a.nf=" + nf + " and a.yf=" + yf + " and a.xmgcid_lb='工程'";
                    }
                    dataString = ConfigurationManager.AppSettings["TzzbIndex_Column"];                    
                }
                DataSet ds = null;
                if (sql != "")
                {
                    ds = Maticsoft.DBUtility.DbHelperOra.Query(sql);
                }

                #region 输出xml串
                ConvertToXml.Convert(ds.Tables[0], dataString, 0, ds.Tables[0].Rows.Count);
                #endregion
            }
        }        
    }
}